//
//  QYGRechargeDetailCell.m
//  wawaji_ios
//
//  Created by 奇艺果 on 2017/12/26.
//  Copyright © 2017年 yiguo qi. All rights reserved.
//

#import "QYGRechargeDetailCell.h"
#import "QYGCoinRecordModel.h"

@interface QYGRechargeDetailCell()

@property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *detailLabel;
@end


@implementation QYGRechargeDetailCell

- (void)setCoinListModel:(QYGCoinListModel *)coinListModel{
    _coinListModel = coinListModel;
    self.detailLabel.text = [NSString stringWithFormat:@"¥%.2f",coinListModel.money];
    NSString *coinStr = [NSString stringWithFormat:@"%ld金币",coinListModel.coin];
    NSMutableAttributedString *owerText = [[NSMutableAttributedString alloc] initWithString:coinStr];
    NSRange changeRange = [owerText.string rangeOfString:@"金币"];
    
    [owerText setAttributes:@{NSFontAttributeName:ScaleFont(12)} range:changeRange];
    if(!coinListModel.coin_award){
        self.nameLabel.attributedText = owerText;
    }else{
        NSString * reward_coin = [NSString stringWithFormat:@"(赠送%ld金币)",coinListModel.coin_award];
        NSMutableAttributedString *appendText = [[NSMutableAttributedString alloc] initWithString:reward_coin];
        [appendText setAttributes:@{
                                  NSForegroundColorAttributeName:[UIColor colorWithHex:@"09bb07"],
                                  NSFontAttributeName:ScaleFont(12),
                                  } ];
        [owerText appendAttributedString:appendText];
        self.nameLabel.attributedText = owerText;
    }
    [self.nameLabel sizeToFit];
    [self.detailLabel sizeToFit];
}


- (void)setSelected:(BOOL)selected{
    if(selected){
        [self viewWithcornerRadius:5 borderWidth:2 borderColor:[UIColor colorWithHex:@"ffda64"]];
    }else{
        [self viewWithcornerRadius:0 borderWidth:0 borderColor:[UIColor clearColor]];
    }
}
#pragma mark setUI

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self initSubView];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
    
}
- (void)initSubView{
    
    [self addSubview:self.iconView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.detailLabel];
}
- (void)setFrame:(CGRect)frame{
    
    frame.size.height  -= ScaleW(6);
    frame.origin.x = ScaleW(15);
    frame.size.width -= ScaleW(30);
    [super setFrame:frame];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.iconView.x = ScaleW(10);
    self.iconView.y = (self.height - self.iconView.height) * 0.5;
    self.nameLabel.x = CGRectGetMaxX(self.iconView.frame) + ScaleW(8);
    self.nameLabel.centerY = self.iconView.centerY;
    self.detailLabel.x = self.width - self.detailLabel.width - ScaleW(10);
    self.detailLabel.centerY = self.iconView.centerY;
    
}
- (UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"recharge_coin"]];
        _iconView.size = CGSizeMake(ScaleW(25), ScaleW(25));
    }
    return _iconView;
}
- (UILabel *)detailLabel{
    if(!_detailLabel){
        _detailLabel = [UILabel labelWithText:@"2.00" setFont:ScaleFont(15) setTextColor:[UIColor colorWithHex:@"333333"] setTextAlignment:NSTextAlignmentRight];
        _detailLabel.numberOfLines = 1;
        _detailLabel.size = CGSizeMake(ScaleW(100), ScaleW(16));
    }
    return _detailLabel;
}
- (UILabel *)nameLabel{
    
    if(!_nameLabel){
        _nameLabel = [UILabel labelWithText:@"50金币" setFont:ScaleFont(18) setTextColor:[UIColor colorWithHex:@"ffb52b"]];
        _nameLabel.numberOfLines = 1;
        [_nameLabel sizeToFit];
    }
    return _nameLabel;
}
@end
